home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
dns
/
name.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
14KB
|
594 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import cStringIO
import struct
import sys
if sys.hexversion >= 33751040:
import encodings.idna as encodings
import dns.exception as dns
NAMERELN_NONE = 0
NAMERELN_SUPERDOMAIN = 1
NAMERELN_SUBDOMAIN = 2
NAMERELN_EQUAL = 3
NAMERELN_COMMONANCESTOR = 4
class EmptyLabel(dns.exception.SyntaxError):
pass
class BadEscape(dns.exception.SyntaxError):
pass
class BadPointer(dns.exception.FormError):
pass
class BadLabelType(dns.exception.FormError):
pass
class NeedAbsoluteNameOrOrigin(dns.exception.DNSException):
pass
class NameTooLong(dns.exception.FormError):
pass
class LabelTooLong(dns.exception.SyntaxError):
pass
class AbsoluteConcatenation(dns.exception.DNSException):
pass
class NoParent(dns.exception.DNSException):
pass
_escaped = {
'"': True,
'(': True,
')': True,
'.': True,
';': True,
'\\': True,
'@': True,
'$': True }
def _escapify(label):
text = ''
for c in label:
if c in _escaped:
text += '\\' + c
continue
if ord(c) > 32 and ord(c) < 127:
text += c
continue
text += '\\%03d' % ord(c)
return text
def _validate_labels(labels):
l = len(labels)
total = 0
i = -1
j = 0
for label in labels:
ll = len(label)
total += ll + 1
if ll > 63:
raise LabelTooLong
if i < 0 and label == '':
i = j
j += 1
if total > 255:
raise NameTooLong
if i >= 0 and i != l - 1:
raise EmptyLabel
class Name(object):
__slots__ = [
'labels']
def __init__(self, labels):
super(Name, self).__setattr__('labels', tuple(labels))
_validate_labels(self.labels)
def __setattr__(self, name, value):
raise TypeError, "object doesn't support attribute assignment"
def is_absolute(self):
if len(self.labels) > 0:
pass
return self.labels[-1] == ''
def is_wild(self):
if len(self.labels) > 0:
pass
return self.labels[0] == '*'
def __hash__(self):
h = 0x0L
for label in self.labels:
for c in label:
h += (h << 3) + ord(c.lower())
return int(h % sys.maxint)
def fullcompare(self, other):
sabs = self.is_absolute()
oabs = other.is_absolute()
if sabs != oabs:
if sabs:
return (NAMERELN_NONE, 1, 0)
else:
return (NAMERELN_NONE, -1, 0)
l1 = len(self.labels)
l2 = len(other.labels)
ldiff = l1 - l2
if ldiff < 0:
l = l1
else:
l = l2
order = 0
nlabels = 0
namereln = NAMERELN_NONE
while l > 0:
l -= 1
l1 -= 1
l2 -= 1
label1 = self.labels[l1].lower()
label2 = other.labels[l2].lower()
if label1 < label2:
order = -1
if nlabels > 0:
namereln = NAMERELN_COMMONANCESTOR
return (namereln, order, nlabels)
elif label1 > label2:
order = 1
if nlabels > 0:
namereln = NAMERELN_COMMONANCESTOR
return (namereln, order, nlabels)
nlabels += 1
order = ldiff
if ldiff < 0:
namereln = NAMERELN_SUPERDOMAIN
elif ldiff > 0:
namereln = NAMERELN_SUBDOMAIN
else:
namereln = NAMERELN_EQUAL
return (namereln, order, nlabels)
def is_subdomain(self, other):
(nr, o, nl) = self.fullcompare(other)
if nr == NAMERELN_SUBDOMAIN or nr == NAMERELN_EQUAL:
return True
return False
def is_superdomain(self, other):
(nr, o, nl) = self.fullcompare(other)
if nr == NAMERELN_SUPERDOMAIN or nr == NAMERELN_EQUAL:
return True
return False
def canonicalize(self):
return []([ x.lower() for x in self.labels ])
def __eq__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] == 0
else:
return False
def __ne__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] != 0
else:
return True
def __lt__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] < 0
else:
return NotImplemented
def __le__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] <= 0
else:
return NotImplemented
def __ge__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] >= 0
else:
return NotImplemented
def __gt__(self, other):
if isinstance(other, Name):
return self.fullcompare(other)[1] > 0
else:
return NotImplemented
def __repr__(self):
return '<DNS name ' + self.__str__() + '>'
def __str__(self):
return self.to_text(False)
def to_text(self, omit_final_dot = False):
if len(self.labels) == 0:
return '@'
if len(self.labels) == 1 and self.labels[0] == '':
return '.'
if omit_final_dot and self.is_absolute():
l = self.labels[:-1]
else:
l = self.labels
s = '.'.join(map(_escapify, l))
return s
def to_unicode(self, omit_final_dot = False):
if len(self.labels) == 0:
return u'@'
if len(self.labels) == 1 and self.labels[0] == '':
return u'.'
if omit_final_dot and self.is_absolute():
l = self.labels[:-1]
else:
l = self.labels
s = []([ encodings.idna.ToUnicode(_escapify(x)) for x in l ])
return s
def to_digestable(self, origin = None):
if not self.is_absolute():
if origin is None or not origin.is_absolute():
raise NeedAbsoluteNameOrOrigin
labels = list(self.labels)
labels.extend(list(origin.labels))
else:
labels = self.labels
dlabels = [ '%s%s' % (chr(len(x)), x.lower()) for x in labels ]
return ''.join(dlabels)
def to_wire(self, file = None, compress = None, origin = None):
if file is None:
file = cStringIO.StringIO()
want_return = True
else:
want_return = False
if not self.is_absolute():
if origin is None or not origin.is_absolute():
raise NeedAbsoluteNameOrOrigin
labels = list(self.labels)
labels.extend(list(origin.labels))
else:
labels = self.labels
i = 0
for label in labels:
n = Name(labels[i:])
i += 1
if compress is not None:
pos = compress.get(n)
else:
pos = None
if pos is not None:
value = 49152 + pos
s = struct.pack('!H', value)
file.write(s)
break
continue
if compress is not None and len(n) > 1:
pos = file.tell()
if pos < 49152:
compress[n] = pos
l = len(label)
file.write(chr(l))
if l > 0:
file.write(label)
continue
if want_return:
return file.getvalue()
def __len__(self):
return len(self.labels)
def __getitem__(self, index):
return self.labels[index]
def __getslice__(self, start, stop):
return self.labels[start:stop]
def __add__(self, other):
return self.concatenate(other)
def __sub__(self, other):
return self.relativize(other)
def split(self, depth):
l = len(self.labels)
if depth == 0:
return (self, dns.name.empty)
elif depth == l:
return (dns.name.empty, self)
elif depth < 0 or depth > l:
raise ValueError, 'depth must be >= 0 and <= the length of the name'
return (Name(self[:-depth]), Name(self[-depth:]))
def concatenate(self, other):
if self.is_absolute() and len(other) > 0:
raise AbsoluteConcatenation
labels = list(self.labels)
labels.extend(list(other.labels))
return Name(labels)
def relativize(self, origin):
if origin is not None and self.is_subdomain(origin):
return Name(self[:-len(origin)])
else:
return self
def derelativize(self, origin):
if not self.is_absolute():
return self.concatenate(origin)
else:
return self
def choose_relativity(self, origin = None, relativize = True):
if origin:
if relativize:
return self.relativize(origin)
else:
return self.derelativize(origin)
else:
return self
def parent(self):
if self == root or self == empty:
raise NoParent
return Name(self.labels[1:])
root = Name([
''])
empty = Name([])
def from_unicode(text, origin = root):
if not isinstance(text, unicode):
raise ValueError, 'input to from_unicode() must be a unicode string'
if not origin is None or isinstance(origin, Name):
raise ValueError, 'origin must be a Name or None'
labels = []
label = u''
escaping = False
edigits = 0
total = 0
if text == u'@':
text = u''
if text:
if text == u'.':
return Name([
''])
for c in text:
if escaping:
if edigits == 0:
if c.isdigit():
total = int(c)
edigits += 1
else:
label += c
escaping = False
elif not c.isdigit():
raise BadEscape
total *= 10
total += int(c)
edigits += 1
if edigits == 3:
escaping = False
label += chr(total)
edigits == 3
if c == u'.' and c == u'\xe3\x80\x82' and c == u'\xef\xbc\x8e' or c == u'\xef\xbd\xa1':
if len(label) == 0:
raise EmptyLabel
labels.append(encodings.idna.ToASCII(label))
label = u''
continue
if c == u'\\':
escaping = True
edigits = 0
total = 0
continue
label += c
if escaping:
raise BadEscape
if len(label) > 0:
labels.append(encodings.idna.ToASCII(label))
else:
labels.append('')
if (len(labels) == 0 or labels[-1] != '') and origin is not None:
labels.extend(list(origin.labels))
return Name(labels)
def from_text(text, origin = root):
if not isinstance(text, str):
if isinstance(text, unicode) and sys.hexversion >= 33751040:
return from_unicode(text, origin)
else:
raise ValueError, 'input to from_text() must be a string'
if not origin is None or isinstance(origin, Name):
raise ValueError, 'origin must be a Name or None'
labels = []
label = ''
escaping = False
edigits = 0
total = 0
if text == '@':
text = ''
if text:
if text == '.':
return Name([
''])
for c in text:
if escaping:
if edigits == 0:
if c.isdigit():
total = int(c)
edigits += 1
else:
label += c
escaping = False
elif not c.isdigit():
raise BadEscape
total *= 10
total += int(c)
edigits += 1
if edigits == 3:
escaping = False
label += chr(total)
edigits == 3
if c == '.':
if len(label) == 0:
raise EmptyLabel
labels.append(label)
label = ''
continue
if c == '\\':
escaping = True
edigits = 0
total = 0
continue
label += c
if escaping:
raise BadEscape
if len(label) > 0:
labels.append(label)
else:
labels.append('')
if (len(labels) == 0 or labels[-1] != '') and origin is not None:
labels.extend(list(origin.labels))
return Name(labels)
def from_wire(message, current):
if not isinstance(message, str):
raise ValueError, 'input to from_wire() must be a byte string'
labels = []
biggest_pointer = current
hops = 0
count = ord(message[current])
current += 1
cused = 1
while count != 0:
if count < 64:
labels.append(message[current:current + count])
current += count
if hops == 0:
cused += count
elif count >= 192:
current = (count & 63) * 256 + ord(message[current])
if hops == 0:
cused += 1
if current >= biggest_pointer:
raise BadPointer
biggest_pointer = current
hops += 1
else:
raise BadLabelType
count = ord(message[current])
current += 1
if hops == 0:
cused += 1
continue
labels.append('')
return (Name(labels), cused)